package com.orientsec.autotest.project.system.newCaseSeq.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.orientsec.autotest.common.constant.UserConstants;
import com.orientsec.autotest.common.utils.StringUtils;
import com.orientsec.autotest.framework.web.domain.Ztree;
import com.orientsec.autotest.framework.web.domain.ZtreeStr;
import com.orientsec.autotest.project.system.dept.domain.Dept;
import com.orientsec.autotest.project.system.newCaseSeq.domain.CaseQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.orientsec.autotest.project.system.newCaseSeq.mapper.NewCaseSeqMapper;
import com.orientsec.autotest.project.system.newCaseSeq.domain.NewCaseSeq;
import com.orientsec.autotest.project.system.newCaseSeq.service.INewCaseSeqService;
import com.orientsec.autotest.common.utils.text.Convert;

/**
 * 案例字段 服务层实现
 * 
 * @author autotest
 * @date 2020-02-17
 */
@Service
public class NewCaseSeqServiceImpl implements INewCaseSeqService 
{
	@Autowired
	private NewCaseSeqMapper newCaseSeqMapper;

	/**
     * 查询案例字段信息
     * 
     * @param caseNo 案例字段ID
     * @return 案例字段信息
     */
    @Override
	public NewCaseSeq selectNewCaseSeqById(String caseNo)
	{
	    return newCaseSeqMapper.selectNewCaseSeqById(caseNo);
	}
	
	/**
     * 查询案例字段列表
     * 
     * @param newCaseSeq 案例字段信息
     * @return 案例字段集合
     */
	@Override
	public List<NewCaseSeq> selectNewCaseSeqList(NewCaseSeq newCaseSeq)
	{
	    return newCaseSeqMapper.selectNewCaseSeqList(newCaseSeq);
	}
	
    /**
     * 新增案例字段
     * 
     * @param newCaseSeq 案例字段信息
     * @return 结果
     */
	@Override
	public int insertNewCaseSeq(NewCaseSeq newCaseSeq)
	{
	    return newCaseSeqMapper.insertNewCaseSeq(newCaseSeq);
	}
	
	/**
     * 修改案例字段
     * 
     * @param newCaseSeq 案例字段信息
     * @return 结果
     */
	@Override
	public int updateNewCaseSeq(NewCaseSeq newCaseSeq)
	{
	    return newCaseSeqMapper.updateNewCaseSeq(newCaseSeq);
	}

	/**
     * 删除案例字段对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteNewCaseSeqByIds(String ids)
	{
		return newCaseSeqMapper.deleteNewCaseSeqByIds(Convert.toStrArray(ids));
	}

	@Override
	public List<ZtreeStr> selectTree(String caseNo) {

		NewCaseSeq newCaseSeq= new NewCaseSeq();
		newCaseSeq.setCaseNo(caseNo);

		List<NewCaseSeq> list= newCaseSeqMapper.selectNewCaseSeqList(newCaseSeq);


		List<ZtreeStr> ztreeStrs = new ArrayList<ZtreeStr>();

		ZtreeStr ztreeStr = new ZtreeStr();
		ztreeStr.setId(caseNo);
		ztreeStr.setName(caseNo);
		ztreeStr.setTitle(caseNo);
		ztreeStr.setpId("root");
		ztreeStrs.add(ztreeStr);
		for (NewCaseSeq newCaseSeq1 : list)
		{
			ztreeStr = new ZtreeStr();
			ztreeStr.setId(newCaseSeq1.getCaseRequestSeq().toString());
			ztreeStr.setpId(newCaseSeq1.getCaseNo());
			ztreeStr.setName(newCaseSeq1.getCaseRequestName());
			ztreeStr.setTitle(newCaseSeq1.getCaseRequestName());
			ztreeStrs.add(ztreeStr);
        }
		return ztreeStrs;

	}

	@Override
	public List<Map> selectCaseDetail(CaseQuery caseQuery) {
		return newCaseSeqMapper.selectCaseDetail(caseQuery);
	}

}
